<?php
namespace Admin\Controller;
use Think\Controller;
class CmsController extends CommonController {
	
	public function _initialize(){
	parent::_initialize();
	//导航母页面显示
	$this->assign("display_nav","cms");	
	$this->model="cms";
	$this->key="cms_id";	
	$this->title_index= L('index');
	$this->title_details=L('details');
	}
	
	public function index(){
		$mist_arr=array('cms_title'=>I('cms_title'));
		$accute_arr=array('cms_cat'=>I("cms_cat"),'cms_isactive'=>I("cms_isactive"),"cms_id"=>I("cms_id"));
		$cookie_arr=array();	
		$con=searchCon($mist_arr,$accute_arr,$cookie_arr);			
		parent::index($con);
	}	
	
	public function addHandle(){
		$oop=M($this->model);
		$oop->create();
		if(I("isupload")=="on"){
			$result=$this->uploadfile($exts=array('jpg', 'gif', 'png', 'jpeg'),$thumb=true);
			$result["status"] || $this->error("invalid uploading...");
			$oop->cms_img_dir=$result['info']['cms_img']['savepath'];
			$oop->cms_img=$result['info']['cms_img']['savename'];
		}
		if($oop->add())
			$this->success(L("add_success"));
		else
			$this->error(L("add_failed"));				
	}
	
	public function updateHandle(){
		//dump(I());exit;
		$oop=M($this->model);
		$oop->create();
		if(I("isupload")=="on"){
			$result=$this->uploadfile($exts=array('jpg', 'gif', 'png', 'jpeg'),$thumb=true);
			$result["status"] || $this->error("invalid uploading...");
			$oop->cms_img_dir=$result['info']['cms_img']['savepath'];
			$oop->cms_img=$result['info']['cms_img']['savename'];
		}
		if($oop->save())
			$this->success(L("update_success"));
		else
			$this->error(L("update_failed"));			
	}
	//删除其中的图片
	public function deleteHandle(){
		$oop=M($this->model);
		$list=$oop->find(I('path.2'));
		//dump($list);exit;
		if($oop->delete()){
			$this->success(L("delete_success"));
			unlink('./Public/Uploads/'.$list['cms_img_dir'].$list['cms_img']);
			unlink('./Public/Uploads/'.$list['cms_img_dir']."thumb_".$list['cms_img']);
			}else{
			$this->error(L("delete_failed"));		
			}
	}
	
}